package com.whq.knowverywell.task;

import android.content.Context;
import android.os.AsyncTask;

import com.whq.knowverywell.business.http.GetRegionSalesDataUtil;
import com.whq.knowverywell.business.http.model.RegionSalesReturn;
import com.whq.knowverywell.util.LogUtil;
import com.whq.knowverywell.util.constant.ModelConstant;

/**
 * 地域分析获取数据
 * @author david
 *
 */
public class DomainTask extends AsyncTask<String, String, RegionSalesReturn> {
    private final static String TAG = DomainTask.class.getSimpleName();

    private Context context = null;
    private ResultDataListener listener;
    private int durationType;
    
    public DomainTask(Context context, ResultDataListener listener, int durationType) {
        this.context = context;
        this.listener = listener;
        this.durationType = durationType;
    }
    
    @Override
    protected RegionSalesReturn doInBackground(String... params) {
        if (this.context == null) {
        	return null;
        }
        
        String orderBy = params[0];
        String sinceCode = params[1];
        LogUtil.i(TAG, "orderBy[" + orderBy + "] sinceCode[" + sinceCode + "]");
        
        RegionSalesReturn domainResult = null;
        switch (durationType) {
		case ModelConstant.DURATION_TYPE_YESTERDAY:
			domainResult = GetRegionSalesDataUtil.getYesterdayDataList(context, orderBy);
			break;
		case ModelConstant.DURATION_TYPE_TODAY:
			domainResult = GetRegionSalesDataUtil.getTodayDataList(context, orderBy);
			break;
		case ModelConstant.DURATION_TYPE_MONTH:
			domainResult = GetRegionSalesDataUtil.getCurrentMonthDataList(this.context, orderBy);
			break;
		case ModelConstant.DURATION_TYPE_YEAR:
			domainResult = GetRegionSalesDataUtil.getCurrentYearDataList(this.context, orderBy);
			break;
		default:
			break;
		}
        
        return domainResult;
    }
    
    @Override
    protected void onPostExecute(RegionSalesReturn huizongResult) {
    	this.listener.handleData(huizongResult);
    }
    
    public interface ResultDataListener {
    	public void handleData(RegionSalesReturn huizongResult);
    }
}
